
#pragma once
#include "../GlobalData/GlobalData.h"
#include <vector>
#include <list>

#define VERY_BIG_FLOAT	10000.0f

static const float SQRT_2 = sqrt(2.0f);

enum Status
{
	Unused = 0,
	Open = 1,
	Closed = 2,
};

struct NodeData
{
	float X;
	float Y;
	float Distance;

	NodeData *NextOpen;
	NodeData *NextClosed;

	NodeData *Parent;

	Status NodeStatus;
};

struct ObjectFound
{
  ObjectFound() : objPtr( NULL ) {}
	int ObjectID;
	float Proportion;
	float Distance;

  ObjectModel* objPtr;
	std::vector<Vector2f> Path;
};

class PathFinder
{
public:
  typedef std::vector<ObjectFound> ObjList;

	PathFinder(int x, int y, float MaxSearch);
	~PathFinder();

	void ResetPathFinder(int x, int y, float MaxSearch);
	int Search(void);
	std::vector<ObjectFound> *GetObjectsList(void);

private:
	void RegisterObject(int ID);
	int RecursiveSearch(void);
	void PutOnOpenList(int x, int y);
	void PutOnClosedList(int x, int y);
	bool NodeValid(int x, int y);
	bool GoodToConsider(int x, int y);
	void RecordPath(int x, int y);
	void DataDump(void);
	void GenerateRandomPath(void);

	std::vector<ObjectFound> ObjectsFound;
	NodeData Grid[GRID_HEIGHT][GRID_WIDTH];
	bool Done;
	int X,Y;
	int SearchDepth;
	float SearchDistance;

	NodeData *OpenList;
	NodeData *ClosedList;
	
	PathFinder();
};
